﻿using System;
using System.IO.IsolatedStorage;
using System.Text;

namespace DateTimeInIsolatedStorage
{
    public class Program
    {
        public static void Main()
        {
            DateTime currentDate = DateTime.Now;

            using (var stream = new IsolatedStorageFileStream("storage", System.IO.FileMode.OpenOrCreate))
            {
                byte[] buffer = new byte[50];
                if (stream.Position != stream.Length)
                {
                    int read = stream.Read(buffer, 0, buffer.Length);
                    string date = Encoding.UTF8.GetString(buffer, 0, read);
                    Console.WriteLine("Last used on: {0}", date);
                }
            }

            using (var stream = new IsolatedStorageFileStream("storage", System.IO.FileMode.Create))
            {
                Console.WriteLine("Current time: {0}", currentDate);
                byte[] buffer = Encoding.UTF8.GetBytes(currentDate.ToString());
                stream.Write(buffer, 0, buffer.Length);
            }
        }
    }
}
